import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:work_tools/values/color.dart';
import 'package:work_tools/values/font.dart';
import 'package:work_tools/values/font_family.dart';


class GrayOutlinedButton extends StatelessWidget {
  final String text;
  final double fontSize;
  final GestureTapCallback? onTap;

  const GrayOutlinedButton(
      {Key? key, this.text = "", this.fontSize = 15, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(4),
            color: Colors.white,
            border: Border.all(color: ColorsValue.grey3, width: 1)),
        child: Text(
          text,
          style: TextStyle(
            color: ColorsValue.textGrey,
            fontSize: fontSize,
          ),
        ),
      ),
    );
  }
}

class BlueOutlinedButton extends StatelessWidget {
  final String text;
  final double fontSize;
  final GestureTapCallback? onTap;

  const BlueOutlinedButton(
      {Key? key, this.text = "", this.fontSize = 15, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 2),
        decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(4),
            color: Colors.white,
            border: Border.all(color: ColorsValue.blue, width: 1)),
        child: Text(
          text,
          style: TextStyle(
            color: ColorsValue.blue,
            fontSize: fontSize,
          ),
        ),
      ),
    );
  }
}

class BottomButton extends StatelessWidget {
  final String text;
  final double fontSize;
  final GestureTapCallback? onTap;

  const BottomButton({Key? key, this.text = "", this.fontSize = 15, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        padding: const EdgeInsets.symmetric(horizontal: 8),
        height: 38,
        decoration: BoxDecoration(
          borderRadius: BorderRadius.circular(6),
          color: Colors.white,
          border: Border.all(color: ColorsValue.blue, width: 1),
          gradient: LinearGradient(
            colors: [ColorsValue.green1, ColorsValue.green2],
            begin: Alignment.centerLeft,
            end: Alignment.centerRight,
          ),
        ),
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: [
            Text(
              text,
              textAlign: TextAlign.center,
              style: TextStyle(
                color: ColorsValue.white,
                fontSize: fontSize,
              ),
            )
          ],
        ),
      ),
    );
  }
}

class BottomDisableButton extends StatelessWidget {
  final String text;
  final double fontSize;
  final GestureTapCallback? onTap;

  const BottomDisableButton({Key? key, this.text = "", this.fontSize = 15, this.onTap})
      : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
          height: 38,
          padding: const EdgeInsets.symmetric(horizontal: 8),
          decoration: BoxDecoration(
            borderRadius: BorderRadius.circular(6),
            color: ColorsValue.grey2,
          ),
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            children: [
              Text(
                text,
                textAlign: TextAlign.center,
                style: TextStyle(
                  color: ColorsValue.white,
                  fontSize: fontSize,
                ),
              ),
            ],
          )
      ),
    );
  }
}

class NotPaddingButton extends StatelessWidget {
  final VoidCallback? onPressed;
  final Widget child;

  const NotPaddingButton({
    Key? key,
    required this.onPressed,
    required this.child,
  }):super(key: key);

  @override
  Widget build(BuildContext context) {
    return TextButton(
      style: ButtonStyle(
        padding: MaterialStateProperty.all(EdgeInsets.zero),
      ),
      onPressed: onPressed,
      child: child,
    );
  }
}

class LineWidget extends StatelessWidget {
  final String title;
  final TextStyle? textStyle;
  final Color? borderColor;

  const LineWidget({
    Key? key,
    required this.title,
    this.textStyle,
    this.borderColor,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 45,
      decoration: BoxDecoration(
        border: Border.all(color: borderColor ?? ColorsValue.white, width: 1),
        borderRadius: const BorderRadius.all(Radius.circular(22)),
      ),
      child: Center(
        child: Text(
          title,
          style: textStyle ??
              TextStyle(
                color: borderColor ?? ColorsValue.white,
                fontSize: Font.font16,
              ),
        ),
      ),
    );
  }
}

class LineButton extends StatelessWidget {
  final String title;
  final TextStyle? textStyle;
  final Color? borderColor;
  final VoidCallback? onPressed;

  const LineButton({
    Key? key,
    required this.title,
    this.textStyle,
    this.borderColor,
    this.onPressed,
  }): super(key: key);

  @override
  Widget build(BuildContext context) {
    return NotPaddingButton(
      onPressed: onPressed,
      child: LineWidget(
        title: title,
        textStyle: textStyle,
        borderColor: borderColor,
      ),
    );
  }
}

class FillButton extends StatelessWidget {
  final String title;
  final TextStyle? textStyle;
  final List<Color>? gradientColor;
  final VoidCallback? onPressed;
  final bool enable;

  const FillButton({
    Key? key,
    required this.title,
    this.textStyle,
    this.gradientColor,
    this.onPressed,
    this.enable = true,
  }):super(key: key);

  @override
  Widget build(BuildContext context) {
    return NotPaddingButton(
      onPressed: enable ? onPressed : ()=>{},
      child: FillWidget(
        enable: enable,
        title: title,
        textStyle: textStyle,
        gradientColor: gradientColor,
      ),
    );
  }
}

class FillWidget extends StatelessWidget {
  final String title;
  final TextStyle? textStyle;
  final List<Color>? gradientColor;
  final bool enable;

  const FillWidget({
    Key? key,
    required this.title,
    this.textStyle,
    this.gradientColor,
    this.enable = true,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    final enableStyle =
        textStyle ?? TextStyle(color: ColorsValue.white, fontSize: Font.font16);
    final disableStyle =
    TextStyle(color: ColorsValue.textGrey, fontSize: Font.font16);
    const disableGradient = LinearGradient(
        colors: [Color(0xFFDFDFDD), Color(0xFFDFDFDD)]);
    final enableGradient = LinearGradient(colors: gradientColor ?? []);
    return Container(
      alignment: Alignment.center,
      height: 45,
      decoration: BoxDecoration(
        gradient: enable ? enableGradient : disableGradient,
        borderRadius: const BorderRadius.all(Radius.circular(22)),
      ),
      child: Text(
        title,
        style: enable ? enableStyle : disableStyle,
      ),
    );
  }
}

enum PrimaryButtonTheme {
  dark, // 深色
  light, // 浅色
  transparent, // 透明背景
}

class PrimaryButton extends StatelessWidget {
  final GestureTapCallback? onTap;
  final Widget child;
  final PrimaryButtonTheme buttonTheme;
  final double? height;

  const PrimaryButton({
    Key? key,
    required this.child,
    this.onTap,
    this.height,
    this.buttonTheme = PrimaryButtonTheme.light,
  }) : super(key: key);

  BoxDecoration get decoration {
    if (buttonTheme == PrimaryButtonTheme.light) {
      return BoxDecoration(
        borderRadius: BorderRadius.circular(4.w),
        color: ColorsValue.white,
        border: Border.all(
          width: 1.0,
          color: ColorsValue.white,
        ),
      );
    }
    if (buttonTheme == PrimaryButtonTheme.transparent) {
      return BoxDecoration(
        borderRadius: BorderRadius.circular(4.w),
        color: Colors.transparent,
        border: Border.all(
          width: 1.0,
          color: ColorsValue.white,
        ),
      );
    }
    return BoxDecoration(
      borderRadius: BorderRadius.circular(4.w),
      color: ColorsValue.black2a,
      border: Border.all(
        width: 1.0,
        color: ColorsValue.white,
      ),
    );
  }
  Color get titleColor {
    if (buttonTheme == PrimaryButtonTheme.light) return ColorsValue.black2a;
    return ColorsValue.white;
  }

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        height: height,
        alignment: Alignment.center,
        decoration: decoration,
        child: Center(
          child: child,
        ),
      ),
    );
  }
}

class PrimaryTextButton extends StatelessWidget {
  final GestureTapCallback? onTap;
  final String title;
  final PrimaryButtonTheme buttonTheme;
  final double? height;

  const PrimaryTextButton({
    Key? key,
    required this.title,
    this.onTap,
    this.height,
    this.buttonTheme = PrimaryButtonTheme.light,
  }) : super(key: key);

  Color get titleColor {
    if (buttonTheme == PrimaryButtonTheme.light) return ColorsValue.black2a;
    return ColorsValue.white;
  }

  @override
  Widget build(BuildContext context) {
    return PrimaryButton(
      onTap: onTap,
      buttonTheme: buttonTheme,
      height: height,
      child: Text(
        title,
        style: TextStyle(
          fontSize: Font.font14,
          color: titleColor,
          fontWeight: FontWeight.w500,
        ),
      ),
    );
  }

}

/// [fontSize] 的默认值为：Font.font12
/// [textColor] 的默认值为：ColorsValue.white
/// [fontWeight] 的默认值为：FontWeight.w500
/// [fontFamily] 的默认值为：FontFamily.SourceHanSansSC
class TextFullButton extends StatelessWidget {
  final disableColor = const Color.fromRGBO(223, 223, 221, 1);
  final String title;
  final VoidCallback? onTap;
  final double? width;
  final double? height;
  final EdgeInsets? padding;
  final EdgeInsets? margin;
  /// [fontSize] 的默认值为：Font.font12
  final double? fontSize;
  /// [textColor] 的默认值为：ColorsValue.white
  final Color? textColor;
  /// [fontWeight] 的默认值为：FontWeight.w500
  final FontWeight? fontWeight;
  /// [fontFamily] 的默认值为：FontFamily.SourceHanSansSC
  final String? fontFamily;
  final bool? disable;

  const TextFullButton({
    Key? key,
    required this.title,
    this.disable,
    this.onTap,
    this.width,
    this.height,
    this.padding,
    this.margin,
    this.fontSize,
    this.textColor,
    this.fontWeight,
    this.fontFamily,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: width,
        height: height,
        padding: padding,
        margin: margin,
        decoration: BoxDecoration(
          color: (disable ?? false) ? disableColor : ColorsValue.black2a,
          borderRadius: BorderRadius.all(Radius.circular(4.w)),
        ),
        child: Center(
          child: Text(
            title,
            style: TextStyle(
              color: textColor ?? ColorsValue.white,
              fontSize: fontSize ?? Font.font12,
              fontFamily:fontFamily ?? FontFamily.SourceHanSansSC,
              fontWeight: fontWeight ?? FontWeight.w500,
            ),
          ),
        ),
      ),
    );
  }
}

class TextOutlinedButton extends StatelessWidget {
  final String title;
  final VoidCallback? onTap;
  final double? width;
  final double? height;
  final EdgeInsets? padding;
  final EdgeInsets? margin;
  final Color? bgColor;
  final double? font;
  final double? borderRadius;

  const TextOutlinedButton({
    Key? key,
    required this.title,
    this.onTap,
    this.width,
    this.height,
    this.padding,
    this.margin,
    this.bgColor,
    this.font,
    this.borderRadius,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return GestureDetector(
      onTap: onTap,
      child: Container(
        width: width,
        height: height,
        padding: padding,
        margin: margin,
        decoration: BoxDecoration(
          color: bgColor ?? ColorsValue.white,
          border: Border.all(color: ColorsValue.black2a,width: 2.w),
          borderRadius: BorderRadius.all(Radius.circular(borderRadius ?? 4.w)),
        ),
        child: Center(
          child: Text(
            title,
            style: TextStyle(
              color: ColorsValue.black2a,
              fontSize: font ?? Font.font12,
              fontFamily: FontFamily.SourceHanSansSC,
              fontWeight: FontWeight.w500,
            ),
          ),
        ),
      ),
    );
  }
}
